package com.spvs.approval.support.callBack;

import com.spvs.approval.domain.ApprovalFromEntity;
import com.spvs.approval.support.ApprovalBusinessCall;
import com.spvs.approval.support.ApprovalBusinessContext;
import com.spvs.system.api.ISpecificationBookService;
import com.spvs.system.api.domain.SpecificationBookAPI;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Component;

/**
 * 技术协议审批回调
 */
@Component
public class JSXYBusinessCallBack implements ApprovalBusinessCall {

    @Autowired
    private ISpecificationBookService specificationBookService;

    @Override
    public Boolean isCall(String type) {
       return ApprovalBusinessContext.TYPE_JSXY.equals(type);
        // return "test".equals(type);
    }

    @Override
    public void callback(ApprovalFromEntity from, Integer userSort,Long userId) {
        // 审批节点+1  技术规格审批需要加1
        userSort += 1;
        SpecificationBookAPI specificationBookAPI = new SpecificationBookAPI();
        specificationBookAPI.setId(Long.parseLong(from.getBusinessId()));
        specificationBookAPI.setNum(userSort);
        specificationBookAPI.setUserId(userId);
        Integer state = 0;
        Integer addr = null;
        switch (from.getStatus()){
            case 101:
                state = 1;
                break;
            case 201:
                state = 2;
                if (userSort==0){
                    addr = 0;
                }else{
                    addr = null;
                }
                break;
            case 301:
                state = 3;
                addr =null;
                break;
            case 302:
                state = 4;
                break;
        }
        specificationBookAPI.setAddr(addr);
        specificationBookAPI.setStatus(state);
        specificationBookService.callBack(specificationBookAPI);
    }
}
